﻿using System;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;

namespace YJKFamilyLibManager.FamilyLibModule
{
	public class DataGridViewDisableCheckBoxCell : DataGridViewCheckBoxCell
	{
		public bool Enabled { get; set; }

		public override object Clone()
		{
			DataGridViewDisableCheckBoxCell dataGridViewDisableCheckBoxCell = (DataGridViewDisableCheckBoxCell)base.Clone();
			dataGridViewDisableCheckBoxCell.Enabled = this.Enabled;
			return dataGridViewDisableCheckBoxCell;
		}

		public DataGridViewDisableCheckBoxCell()
		{
			this.Enabled = true;
		}

		protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
		{
			if (!this.Enabled)
			{
				if ((paintParts & DataGridViewPaintParts.Background) == DataGridViewPaintParts.Background)
				{
					SolidBrush solidBrush = new SolidBrush(cellStyle.BackColor);
					graphics.FillRectangle(solidBrush, cellBounds);
					solidBrush.Dispose();
				}
				if ((paintParts & DataGridViewPaintParts.Border) == DataGridViewPaintParts.Border)
				{
					this.PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
				}
				CheckBoxState state = CheckBoxState.MixedDisabled;
				Size glyphSize = CheckBoxRenderer.GetGlyphSize(graphics, state);
				Point glyphLocation = new System.Drawing.Point(cellBounds.X, cellBounds.Y);
				glyphLocation.X += (cellBounds.Width - glyphSize.Width) / 2;
				glyphLocation.Y += (cellBounds.Height - glyphSize.Height) / 2;
				CheckBoxRenderer.DrawCheckBox(graphics, glyphLocation, state);
				return;
			}
			base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
		}
	}
}
